<script>
import outMain from "@/components/outMain.vue";
import elSelect from "@/components/public/elSelect.vue";
import { ElMessage, ElMessageBox } from "element-plus";
import { Accreditation, AccreditationDelete } from "@/http/api";

export default {
  components: { outMain, elSelect },
  name: "",
  data() {
    return {
      tableData: [{}],
      queryData: {
        project_name: "",
        page: 1,
        per_page: 10,
      },
      total: 0,
    };
  },
  props: {},
  setup() {},
  methods: {
    deleteFn(row) {
      ElMessageBox.confirm("确定删除选择的共享客户吗?", "删除提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        AccreditationDelete({
          project_id: row.project_id,
        }).then((res) => {
          if (res.data.code == 1) {
            ElMessage({
              type: "success",
              message: "删除成功",
            });
            this.getData();
          }
        });
      });
    },
    addFn(id) {
      this.$router.push({ path: "/workListAdd", query: { id: id } });
    },
    detailFn(id) {
      this.$router.push({ path: "/workListDetail", query: { id: id } });
    },
    getData() {
      Accreditation(this.queryData).then((res) => {
        if (res.data.code == 1) {
          this.tableData = res.data.data.data;
          this.total = res.data.data.total;
        }
      });
    },
  },
  mounted() {},
  created() {
    this.getData();
  },
};
</script>
<template>
  <outMain>
    <div class="tableCont">
      <div class="tableName flexCont">
        <div>共享列表({{ total }})</div>
      </div>
      <div class="tableSerch">
        <div class="serchLeft">
          <btn value="新增" @ok="addFn"></btn>
        </div>
        <div class="serchRight">
          <el-form class="flexCenter" :inline="true">
            <el-form-item>
              <el-input
                clearable
                @clear="getData"
                @keyup.enter="getData"
                v-model="queryData.project_name"
                placeholder="请输入产品名称"
              />
            </el-form-item>
            <btn value="搜索" @click="getData"></btn>
          </el-form>
        </div>
      </div>
      <el-table class="tableMain" :data="tableData" stripe style="width: 100%">
        <el-table-column
          prop="project_number"
          show-overflow-tooltip
          label="项目编号"
          width="120"
        />
        <el-table-column
          prop="project_name"
          show-overflow-tooltip
          label="产品名称"
          width="300"
        />
        <el-table-column
          prop="accreditation_money"
          show-overflow-tooltip
          label="服务器年费"
        >
          <template #default="{ row }">{{ row.project_price }}</template>
        </el-table-column>
        <el-table-column
          prop="create_time"
          show-overflow-tooltip
          label="创建时间"
        />
        <el-table-column
          prop="accreditation_money"
          show-overflow-tooltip
          width="200"
          label="剩余时间"
        >
          <template #default="{ row }">{{ row.expiration_day }} 天</template>
        </el-table-column>
        <el-table-column
          prop="expiration_time"
          width="200"
          show-overflow-tooltip
          label="到期时间"
        />
        <el-table-column width="100" label="操作">
          <template #default="{ row }">
            <div class="tableCtrl">
              <div class="blueText ctrlText" @click="addFn(row.project_id)">
                编辑
              </div>
              <div class="redText ctrlText" @click="deleteFn(row)">删除</div>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div class="pageCont">
        <el-pagination
          v-model:currentPage="queryData.page"
          v-model:page-size="queryData.per_page"
          background
          layout="total, prev, pager, next, jumper"
          :total="total"
          @size-change="getData"
          @current-change="getData"
        />
      </div>
    </div>
  </outMain>
</template>
<style scoped lang="less"></style>
